var express = require('express');
var Ticktype = require('../models/ticktype');

var ticketinfo = express.Router();

//根据id处理门票具体信息页
ticketinfo.get('/getTickInfo/:id', function (req, res){
    Ticktype.findOne({
        $or:[
            {ticket_typeid: req.params.id},
        ]
    },function (err, data) {
        res.status(200).json(data)
    })
});

function concatImg(data) {
    var data2 = {src: data.url};
    data2.img = data.url;
    var imgGroup = [
        {src:'http://127.0.0.1:3000/public/img/jp9.jpg', img:'http://127.0.0.1:3000/public/img/jp9.jpg'},
        {src:'http://127.0.0.1:3000/public/img/jp6.jpg', img:'http://127.0.0.1:3000/public/img/jp6.jpg'},
        {src:'http://127.0.0.1:3000/public/img/jp7.jpg', img:'http://127.0.0.1:3000/public/img/jp7.jpg'},
        {src:'http://127.0.0.1:3000/public/img/jp8.jpg', img:'http://127.0.0.1:3000/public/img/jp8.jpg'},
    ];
    imgGroup.unshift(data2);
    return imgGroup;
}

//设置门票信息详情的api
var imgGroup = [
    {src:'http://127.0.0.1:3000/public/img/jp9.jpg', img:'http://127.0.0.1:3000/public/img/jp9.jpg'},
    {src:'http://127.0.0.1:3000/public/img/jp6.jpg', img:'http://127.0.0.1:3000/public/img/jp6.jpg'},
    {src:'http://127.0.0.1:3000/public/img/jp7.jpg', img:'http://127.0.0.1:3000/public/img/jp7.jpg'},
    {src:'http://127.0.0.1:3000/public/img/jp8.jpg', img:'http://127.0.0.1:3000/public/img/jp8.jpg'},
];
ticketinfo.get('/getImage/:id', function (req, res){
    Ticktype.findOne({
        $or:[
            {ticket_typeid: req.params.id},
        ]
    },function (err, data) {
        res.status(200).json(concatImg(data));
    })
});

module.exports = ticketinfo;
